package net.wanho.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import net.wanho.mapper.UnitMapper;
import net.wanho.po.Unit;
import net.wanho.service.UnitService;
import net.wanho.vo.PageInfo;
import org.springframework.stereotype.Service;

/**
 * @author 32033
 * @description 针对表【unit(规格单位表)】的数据库操作Service实现
 * @createDate 2025-01-11 17:01:23
 */
@Service
public class UnitServiceImpl extends ServiceImpl<UnitMapper, Unit>
        implements UnitService {

    @Override
    public PageInfo<Unit> getSupplyPage(int pageNum, int pageSize, Unit unit) {
        Page<Unit> page = new Page<>(pageNum, pageSize);
        LambdaQueryWrapper<Unit> wrapper = new LambdaQueryWrapper<>();
        wrapper.like(!ObjectUtils.isEmpty(unit.getUnitName()), Unit::getUnitName, unit.getUnitName());
        wrapper.like(!ObjectUtils.isEmpty(unit.getUnitDesc()), Unit::getUnitDesc, unit.getUnitDesc());
        this.page(page, wrapper);

        PageInfo<Unit> pageInfo = new PageInfo<>();
        pageInfo.setPageNum(page.getCurrent());
        pageInfo.setPageSize(page.getSize());
        pageInfo.setTotalNum(page.getTotal());
        pageInfo.setPageCount(page.getCurrent());
        pageInfo.setResultList(page.getRecords());
        pageInfo.setLimitIndex(page.offset());
        return pageInfo;

    }
}




